﻿using ExamRoomAllocationManagement.Services;
using Microsoft.AspNetCore.Mvc;
using Xmu.ExamRoomAllocationManagement.Services;
using Xmu.Stores.Models;

namespace UserStores.Controllers
{
    [Route("/api/[controller]")]
    public class ExamRoomController : Controller
    {
        private ExamRoomService examRoomService;
        public ExamRoomController(ExamRoomService examRoomService)
        {
            this.examRoomService = examRoomService;
        }

        [HttpGet]
        public IActionResult GetExamRooms([FromQuery] int pageIndex, [FromQuery] int pageSize)
        {
            Console.WriteLine("*** this is controller *****");
            (object data, object msg) = examRoomService.GetExamRooms(pageIndex, pageSize);
            return Ok(new
            {
                msg,
                data
            });
        }

        [HttpGet("{id}")]
        public IActionResult GetExamRoom(Guid id)
        {
            (object data, object msg) = examRoomService.GetExamRoom(id);
            return Ok(new
            {
                msg,
                data
            });
        }

        [HttpPost]
        public IActionResult AddExamRoom([FromBody] ExamRoom examRoom)
        {
            var (success, msg) = examRoomService.AddExamRoom(examRoom);
            if (success) return Ok();
            else return BadRequest(msg);
        }


        [HttpDelete]
        public IActionResult DeleteExamRoom(Guid id)
        {
            var (success, msg) = examRoomService.DeleteExamRoom(id);
            if (success) return Ok();
            else return BadRequest(msg);
        }

    }
}
